﻿@model Bricks.Site.Models.ProjectContractView
@{
    ViewBag.Title = "ShowFinishAlter";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}

<head>
    <title></title>
    <script type="text/javascript">
        $(function () {
            var projectID = $("#hProjectID").val();
            var contractID = $("#hContractID").val();
            $('#myDataGrid').datagrid({   //定位到Table标签，Table标签的ID是myDataGrid
                //   ActionInfo是控制器，GetData是控制器中获取用户数据的一个Action
                title: '',
                url: '/Alter/GetFinishAlterList?projectID=' + projectID + '&contractID=' + contractID,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                rownumbers: true,
                remoteSort: false,
                fitColumns: true,
                idField: 'ID',
                singleSelect: true,
                toolbar: '#actionToolBar',
                columns: [[
                    { title: 'ID', field: 'ID', hidden: true },
                    {
                        field: 'IsChecked',
                        formatter: function (value, row, index) {
                            return '<input type="checkbox" onclick="ChangeChecked(' + index + ');" />';
                        }
                    },
                    { title: '变更申请编码', field: 'AlterCode', width: 100, sortable: true },
                    { title: '变更申请名称', field: 'AlterName', width: 100, sortable: true },
                ]]
            });
        });

        function ChangeChecked(index) {
            $("#myDataGrid").datagrid("selectRow", index);  //选中指定行
            var selectedRow = $("#myDataGrid").datagrid("getSelected");  //获取选中行记录
            if (selectedRow) {
                //此处是为了取出IsChecked的值
                if (selectedRow.IsChecked == false) {
                    selectedRow.IsChecked = true;
                }
                else {
                    selectedRow.IsChecked = false;
                }
            }
        }

        //全选或者全不选
        function SetAll(check) {
            $("input:checkbox").each(function () {
                $(this)[0].checked = check;
            });
            var alterList = $('#myDataGrid').datagrid('getData').rows;
            for (var i = 0; i < alterList.length; i++) {
                alterList[i].IsChecked = check;
            }
        }

        //反选
        function OppositeChoose() {
            $("input:checkbox").each(function (index) {
                $("#myDataGrid").datagrid("selectRow", index);  //选中指定行
                var selectedRow = $("#myDataGrid").datagrid("getSelected");  //获取选中行记录
                if ($(this)[0].checked) {
                    $(this)[0].checked = false;
                    selectedRow.IsChecked = false;
                }
                else {
                    $(this)[0].checked = true;
                    selectedRow.IsChecked = true;
                }
            });
        }

        function SaveSelectAlter() {
            var idArray = new Array;
            var codeArray = new Array;
            var alterList = $('#myDataGrid').datagrid('getData').rows;
            for (var i = 0; i < alterList.length; i++)
            {
                if (alterList[i].IsChecked) {
                    idArray[idArray.length] = alterList[i].ID;
                    codeArray[codeArray.length] = alterList[i].AlterCode;
                }
            }
            if (idArray.length == 0) {
                $.messager.alert('操作提示', '请选择变更申请！', 'info');
            }
            else {
                window.parent.CloseWindow(0);
                window.parent.SetSelectAlterReturnValue(idArray, codeArray);
            }
        }
    </script>
</head>
<body>
    <div style="padding:5px;">
        <input type="hidden" id="hProjectID" name="ID" value="@Model.ProjectID" />
        <input type="hidden" id="hContractID" name="ID" value="@Model.ContractID" />
        <div region="top" style="height:180px;">
            <table id="myDataGrid" title="" fit="true"></table>
            <div id="actionToolBar">
                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='SetAll(true)' data-options='plain:true,iconCls:"icon-bestseller"'>全选</a>
                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='SetAll(false)' data-options='plain:true,iconCls:"icon-blue_lego"'>全不选</a>
                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='OppositeChoose()' data-options='plain:true,iconCls:"icon-caution"'>反选</a>
            </div>
        </div>
        <div style="margin-left: 5px; margin-top: 5px; text-align: right;">
            <input type="button" id="btnSave" value="确定" onclick="SaveSelectAlter();" />
            <input type="button" id="btnCancel" value="取消" onclick="window.parent.CloseWindow(0);" />
        </div>
    </div>
</body>
